package com.huawei.su;

import java.util.Stack;

/**
 *
 */
public class BM43 {
    public static void main(String[] args) {
        BM43 bm43 = new BM43();
        bm43.push(9);
        bm43.push(1);
        bm43.push(6);

        System.out.println(bm43.min());
        bm43.pop();
        bm43.pop();
        System.out.println(bm43.min());

    }

    private static final Stack<Integer> stack = new Stack<>();

    public void push(int node) {
        stack.push(node);
    }

    public void pop() {
        stack.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int min() {
        Stack<Integer> helperStack = new Stack<>();
        int MIN = Integer.MAX_VALUE;
        while (true) {
            if (stack.isEmpty()) {
                break;
            }
            Integer pop = stack.pop();
            helperStack.push(pop);
            MIN = MIN < pop ? MIN : pop;
        }

        while (true) {
            if (helperStack.isEmpty()) {
                break;
            }
            stack.push(helperStack.pop());
        }
        return MIN;
    }
}
